package wk.demo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.luoye.bzijkplayer.R;

import java.util.Date;
import java.util.List;
import wk.demo.bean.HistoryReadBean;
import wk.demo.tool.MyTimeTool;

public class HistoryAdapter extends RecyclerView.Adapter {

    private List<HistoryReadBean> list;
    private Context context ;

    public HistoryAdapter(Context context, List<HistoryReadBean> list)  {
        this.context=context ;
        this.list = list;
    }


    public void removeItem(int position)   {
        list.remove(position);
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)  {
        LayoutInflater mInflater=LayoutInflater.from(context);
        return new MyViewHolder( mInflater.inflate(R.layout.list_item_lay, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position)  {
        final MyViewHolder viewHolder = (MyViewHolder) holder;
        HistoryReadBean  bean = list.get(position) ;
        String time= MyTimeTool.getCurrentDataStr(1 , new Date(bean.getSaveTime())) ;
        viewHolder.fileName.setText( String.format("%s %s" ,bean.getFileName() ,time) );
        viewHolder.filePath.setText(bean.getFilePaht());
    }


    @Override
    public int getItemCount()  {
        return list != null ? list.size() : 0;
    }



    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView fileName;
        TextView filePath;
        public LinearLayout layout;

        MyViewHolder(View itemView) {
            super(itemView);
            layout =    itemView.findViewById(R.id.item_layout);
            fileName =  itemView.findViewById(R.id.fileName);
            filePath =  itemView.findViewById(R.id.filePath);
        }
    }

}
